function menu(key){
    if(key=="consult"){
        server.loadindex('page/teacher/teacherindex/serviceconfig/serviceconfig');
    }else if(key=="info"){
        server.loadindex('page/teacher/teacherindex/infoconfig/infoconfig');
    }else if(key=="desc"){
        server.loadindex('page/teacher/teacherindex/descconfig/descconfig');
    }else if(key=="ask"){
        server.loadindex('page/teacher/teacherindex/askconfig/askconfig');
    }
};
function orderlist(menu) {
    server.loadindex('page/order/teacherorderlist/teacherorderlist','menu='+menu);
};
function roborder(orderId){
    server.req('wechat/order/roborder',{orderId:orderId},function (res) {
        if(res.code==0){
            pop_up("抢单成功，请尽快回答会员的问题");
            server.loadindex('page/teacher/teacherindex/teacherindex');
        }else{
            pop_up(res.msg);
        }

    })
};
//我的人脉
function myRenmai(){
    server.loadindex('page/user/renmai/renmai');
}
$(function(){
    //获取当前用的信息
    server.getUserInfo(function (e) {
        var userinfo = e;
        // console.log(userinfo)
        server.loadData("#userinfo",userinfo);
        $("#membername").text(userinfo.nickname);
        $("#headimage").attr("src",userinfo.headimgurl);
        $("#userinfo").css('background-image','url('+userinfo.headimgurl+')');
        // $("#followNumber").text(userinfo.followNumber);
    });

    //获取当前用户的大师资格申请
    server.req('wechat/teacher/getByMemberId',{},function (e) {
        if(e.code==0){
            console.log('i am a teacher');
            console.log(e);
            var data = e.data;
            if(e.data==null){
                $("#nodata").css('display','block');
                $("#nodataimage").attr('src','img/icons/search.png');
                $("#nodatatext").text('您还没通过大师入驻申请');
            }
            else{
                if(data.status==2){
                    server.loadData("#userinfo",data);
                    $("#nodata").css('display','none');
                    $("#content").css('visibility','visible');

                    //设备banner背景
                    $("#userinfo").css('background-image','url('+data.bgImage+')');
                    // $("#membername").text(data.nickname);
                    console.log(data.fansNumber+"--");
                    $("#fansNumber").text(data.fansNumber||0);

                }else{
                    // console.log("..........")
                        $("#nodata").css('display','block');
                        $("#nodataimage").attr('src','img/icons/search.png');
                        $("#nodatatext").text('您还没通过大师入驻申请');
                        }
            }
        }
    });

    //获取当前会员钱包
    server.req('wechat/memberwallet/getbymemberid',{},function (e) {
        console.log("wallet:")
        console.log(e);
        if(e.code==0){
            var data = e.data;
            $("#commission").text(data.commissionBalance);
            $("#balance").text((data&&data.balance)||0);
            server.loadData("#userinfo",data);
        }

    });

    //获取闪测的最新订单
    server.req('wechat/order/newquickask',{},function (res) {
        // console.log("-------new quick ask order---------")
        // console.log(res)
        if(res.code==0){
            server.loadData(".quickask",res);
            var data = res.data;

            if(data.length>0){
                data.forEach(function (item,index) {
                    server.loadData(".Corder-list-item-goods"+item.id,data[index]);

                })
            }else{
                $("#nodata2").css("display","block");
            }
        }
    })
});
